<template>
	<view>
		<u-cell-item title="新消息提醒">
			<u-switch active-color='#FF365D' @change="setMessagesReceiving" slot="right-icon"
				v-model="newMessageReminder"></u-switch>
		</u-cell-item>
		<u-cell-item title="声音提醒">
			<u-switch active-color='#FF365D' @change="setMessagesReceiving" slot="right-icon" v-model="soundPrompt">
			</u-switch>
		</u-cell-item>
	</view>
</template>

<script>
	export default {
		data() {
			return {
				newMessageReminder: false,
				soundPrompt: false,
				msgObg: {}
			};
		},
		mounted() {
			this.getMessagesReceiving()
		},
		methods: {
			setMessagesReceiving() {
				this.$u.api.setMessagesReceiving({
					...this.msgObg,
					newMessageReminder: this.newMessageReminder ? 1 : 2,
					soundPrompt: this.soundPrompt ? 1 : 2,
				}).then(res => {
					this.getMessagesReceiving()
				})
			},
			// GET /app/appUser/getMessagesReceiving
			getMessagesReceiving() {
				this.$u.api.getMessagesReceiving().then(res => {
					console.log(res)
					const {
						newMessageReminder,
						soundPrompt
					} = res
					this.msgObg = res
					this.newMessageReminder = newMessageReminder == 1 ? true : false
					this.soundPrompt = soundPrompt == 1 ? true : false
				})
			}

		}
	}
</script>

<style lang="scss">

</style>
